package cs236369.hw5.servlet.listeners;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import cs236369.hw5.db.HibernateUtil;

/**
 * this listener will load hibernate session factory when the server starts
 * @author Dror Baum
 * @author Amir Hasson
 *
 */
public class HibernateServletListener implements ServletContextListener
{

	public void contextInitialized(ServletContextEvent event)
	{
		// Just call the static initializer of that class
		new Thread()
		{
			@Override
			public void run()
			{
				HibernateUtil.getSessionFactory();
			}
			
		}.run();
	}

	public void contextDestroyed(ServletContextEvent event)
	{
		HibernateUtil.getSessionFactory().close(); // Free all resources
	}
	
}
